<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="MySQL," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="mysql常用操作&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;有一个图形管理mysql的工具叫phpmyadmin，而如何在命令行下面来管理和操作mysql。 1mysql&amp;gt; show databases;  查看某个库的表12mysql&amp;gt; use mysql;mysql&amp;gt; show tables;  查看表的字段1mysql&amp;">
<meta name="keywords" content="MySQL">
<meta property="og:type" content="article">
<meta property="og:title" content="mysql常用操作">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/MySQL/13. mysql常用操作/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="mysql常用操作&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;有一个图形管理mysql的工具叫phpmyadmin，而如何在命令行下面来管理和操作mysql。 1mysql&amp;gt; show databases;  查看某个库的表12mysql&amp;gt; use mysql;mysql&amp;gt; show tables;  查看表的字段1mysql&amp;">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/01.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/02.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/03.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/04.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/05.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/06.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/07.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/08.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/09.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/10.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/11.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/12.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/13.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/14.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/15.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/16.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/17.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/18.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/19.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/20.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/21.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/22.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/23.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/24.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/25.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/26.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/27.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/28.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/29.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/30.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/31.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/32.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/33.png?raw=true">
<meta property="og:updated_time" content="2017-09-01T09:00:56.751Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="mysql常用操作">
<meta name="twitter:description" content="mysql常用操作&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;有一个图形管理mysql的工具叫phpmyadmin，而如何在命令行下面来管理和操作mysql。 1mysql&amp;gt; show databases;  查看某个库的表12mysql&amp;gt; use mysql;mysql&amp;gt; show tables;  查看表的字段1mysql&amp;">
<meta name="twitter:image" content="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/01.png?raw=true">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/MySQL/13. mysql常用操作/"/>





  <title>mysql常用操作 | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/MySQL/13. mysql常用操作/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">mysql常用操作</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T02:06:42+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="mysql常用操作"><a href="#mysql常用操作" class="headerlink" title="mysql常用操作"></a>mysql常用操作</h1><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;有一个图形管理mysql的工具叫phpmyadmin，而如何在命令行下面来管理和操作mysql。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show databases;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/01.png?raw=true" alt=""></p>
<h2 id="查看某个库的表"><a href="#查看某个库的表" class="headerlink" title="查看某个库的表"></a>查看某个库的表</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">mysql&gt; use mysql;</div><div class="line">mysql&gt; show tables;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/02.png?raw=true" alt=""></p>
<h2 id="查看表的字段"><a href="#查看表的字段" class="headerlink" title="查看表的字段"></a>查看表的字段</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; desc pre_ucenter_vars;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/03.png?raw=true" alt=""></p>
<h2 id="查看建表的语句"><a href="#查看建表的语句" class="headerlink" title="查看建表的语句"></a>查看建表的语句</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show create table pre_ucenter_vars\G;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/04.png?raw=true" alt=""></p>
<h2 id="当前是哪个用户"><a href="#当前是哪个用户" class="headerlink" title="当前是哪个用户"></a>当前是哪个用户</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; select user();</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/05.png?raw=true" alt=""></p>
<h2 id="查看当前库"><a href="#查看当前库" class="headerlink" title="查看当前库"></a>查看当前库</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; select database();</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/06.png?raw=true" alt=""></p>
<h2 id="创建库"><a href="#创建库" class="headerlink" title="创建库"></a>创建库</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; create database yanyi;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/07.png?raw=true" alt=""></p>
<h2 id="创建表"><a href="#创建表" class="headerlink" title="创建表"></a>创建表</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; create table tb1 (`id` int(4), `name` char(40)) ENGINE=MyISAM DEFAULT CHARSET=gbk;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;tb1 是表名；第一个字段是 <code>id</code>,格式是 int ，长度 4位；第二个字段 <code>name</code> 格式是 char 长度 40；指定 ENGINE 为 MyISAM ；字符集 DEFAULT CHARSET 为 gbk。</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/08.png?raw=true" alt=""></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建完成后查看</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/09.png?raw=true" alt=""></p>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/10.png?raw=true" alt=""></p>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/11.png?raw=true" alt=""></p>
<h2 id="插入数据"><a href="#插入数据" class="headerlink" title="插入数据"></a>插入数据</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; insert into tb1 values (1,<span class="string">'yanyi'</span>);</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/12.png?raw=true" alt=""></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;还可以继续插入</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/13.png?raw=true" alt=""></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;也可以只插入一个字段</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; insert into tb1 (`id`) values (2);</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/14.png?raw=true" alt=""></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; insert into tb1 (`name`) values (<span class="string">'docker'</span>);</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/15.png?raw=true" alt=""></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; insert into tb1 (`name`,`id`) values (<span class="string">'redis'</span>,6);</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/16.png?raw=true" alt=""></p>
<h2 id="查看数据库版本"><a href="#查看数据库版本" class="headerlink" title="查看数据库版本"></a>查看数据库版本</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; select version();</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/17.png?raw=true" alt=""></p>
<h2 id="查看-mysql-状态"><a href="#查看-mysql-状态" class="headerlink" title="查看 mysql 状态"></a>查看 mysql 状态</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show status;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/18.png?raw=true" alt=""></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;也可以用 like 过滤，% 通配</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show status like <span class="string">'%running'</span>;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/19.png?raw=true" alt=""></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show status like <span class="string">'%buffer%'</span>;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/20.png?raw=true" alt=""></p>
<h2 id="修改-mysql-参数"><a href="#修改-mysql-参数" class="headerlink" title="修改 mysql 参数"></a>修改 mysql 参数</h2><p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/21.png?raw=true" alt=""></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">mysql&gt; <span class="built_in">set</span> global max_connections=200;</div><div class="line">mysql&gt; show variables like <span class="string">'max_connections'</span>;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/22.png?raw=true" alt=""></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果记不住也可以用 % 通配</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show variables like <span class="string">'max_connec%'</span>;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/23.png?raw=true" alt=""></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;不过这些方法，重启就会变回以前配置，要永久生效需更改 /etc/my.cnf</p>
<h2 id="查看-mysql-队列"><a href="#查看-mysql-队列" class="headerlink" title="查看 mysql 队列"></a>查看 mysql 队列</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show processlist;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/24.png?raw=true" alt=""></p>
<h2 id="查看-mysql-变量"><a href="#查看-mysql-变量" class="headerlink" title="查看 mysql 变量"></a>查看 mysql 变量</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show variables;</div></pre></td></tr></table></figure>
<h2 id="创建普通用户并授权"><a href="#创建普通用户并授权" class="headerlink" title="创建普通用户并授权"></a>创建普通用户并授权</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">mysql&gt; grant all on *.* to user1 identified by <span class="string">'123456'</span>;</div><div class="line"></div><div class="line">mysql&gt; grant all on discuz.* to <span class="string">'user2'</span>@<span class="string">'192.168.0.%'</span> identified by <span class="string">'123456'</span>；</div><div class="line"></div><div class="line">mysql&gt; grant all on discuz.* to <span class="string">'user3'</span>@<span class="string">'%'</span> identifined by <span class="string">'123456'</span>;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;all 代表所有权限；<em>.</em>代表所有库里的所有表，discuz.*代表 discuz 库里的所有表；to 后边是用户名；@ 后边是客户端 ip ，192.168.0.%代表整个网段，% 代表通配，直接用 % 代替 ip 就表示所有网段；identfied by 后边是密码。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;用户创建完以后还没有即时生效，需要刷新下权限命令如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; flush privileges;</div></pre></td></tr></table></figure>
<h2 id="更改密码"><a href="#更改密码" class="headerlink" title="更改密码"></a>更改密码</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; update mysql.user <span class="built_in">set</span> password=password(<span class="string">"newpwd"</span>) <span class="built_in">where</span> user=<span class="string">'username'</span>;</div></pre></td></tr></table></figure>
<h2 id="查询"><a href="#查询" class="headerlink" title="查询"></a>查询</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; select count(*) from mysql.user;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/25.png?raw=true" alt=""></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; select * from mysql.db;select * from mysql.db <span class="built_in">where</span> host like <span class="string">'10.0.%'</span>\G;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/26.png?raw=true" alt=""></p>
<h2 id="插入"><a href="#插入" class="headerlink" title="插入"></a>插入</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; update tb1 <span class="built_in">set</span> id=5 <span class="built_in">where</span> name = <span class="string">'docker'</span>;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/27.png?raw=true" alt=""></p>
<h2 id="清空表"><a href="#清空表" class="headerlink" title="清空表"></a>清空表</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; truncate table yanyi.tb1;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;yanyi是库名，tb1是表名，清空以后表还在。</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/28.png?raw=true" alt=""></p>
<h2 id="删除表"><a href="#删除表" class="headerlink" title="删除表"></a>删除表</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; delete from tb1 <span class="built_in">where</span> name=<span class="string">'redis'</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这是删除表中指定的行</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/29.png?raw=true" alt=""></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; drop table tb1;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这是删除整个表</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/30.png?raw=true" alt=""></p>
<h2 id="删除数据库"><a href="#删除数据库" class="headerlink" title="删除数据库"></a>删除数据库</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; drop database yanyi;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/31.png?raw=true" alt=""></p>
<h2 id="修复表"><a href="#修复表" class="headerlink" title="修复表"></a>修复表</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; repair table discuz.pre_forum_post;</div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/32.png?raw=true" alt=""></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;以上就是一些常用的 mysql相关操作。还有个知识点，在 shell 的命令下去执行 mysql 的操作</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@lamp ~]<span class="comment"># mysql -uroot -pyanyi mysql -e "show tables"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;-e 前面的 mysql 指的是库的名字， -e 选项后面双引号括起来的就是 mysql 的命令。 </p>
<p><img src="https://github.com/hcldirgit/image/blob/master/mysql%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/33.png?raw=true" alt=""></p>
<h2 id="授权超级用户"><a href="#授权超级用户" class="headerlink" title="授权超级用户"></a>授权超级用户</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">grant all privileges on *.* to <span class="string">'tangnanbing'</span>@<span class="string">'%'</span> identified by <span class="string">'1qaz@WSX'</span> with grant option;</div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/MySQL/" rel="tag"># MySQL</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/MySQL/12. mysql备份与恢复/" rel="next" title="mysql备份与恢复">
                <i class="fa fa-chevron-left"></i> mysql备份与恢复
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/MySQL/15. MySQL存储引擎MyISAM与InnoDB的优劣/" rel="prev" title="MySQL存储引擎MyISAM与InnoDB的优劣">
                MySQL存储引擎MyISAM与InnoDB的优劣 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#mysql常用操作"><span class="nav-number">1.</span> <span class="nav-text">mysql常用操作</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#查看某个库的表"><span class="nav-number">1.1.</span> <span class="nav-text">查看某个库的表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看表的字段"><span class="nav-number">1.2.</span> <span class="nav-text">查看表的字段</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看建表的语句"><span class="nav-number">1.3.</span> <span class="nav-text">查看建表的语句</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#当前是哪个用户"><span class="nav-number">1.4.</span> <span class="nav-text">当前是哪个用户</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看当前库"><span class="nav-number">1.5.</span> <span class="nav-text">查看当前库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建库"><span class="nav-number">1.6.</span> <span class="nav-text">创建库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建表"><span class="nav-number">1.7.</span> <span class="nav-text">创建表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#插入数据"><span class="nav-number">1.8.</span> <span class="nav-text">插入数据</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看数据库版本"><span class="nav-number">1.9.</span> <span class="nav-text">查看数据库版本</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看-mysql-状态"><span class="nav-number">1.10.</span> <span class="nav-text">查看 mysql 状态</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#修改-mysql-参数"><span class="nav-number">1.11.</span> <span class="nav-text">修改 mysql 参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看-mysql-队列"><span class="nav-number">1.12.</span> <span class="nav-text">查看 mysql 队列</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看-mysql-变量"><span class="nav-number">1.13.</span> <span class="nav-text">查看 mysql 变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建普通用户并授权"><span class="nav-number">1.14.</span> <span class="nav-text">创建普通用户并授权</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#更改密码"><span class="nav-number">1.15.</span> <span class="nav-text">更改密码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查询"><span class="nav-number">1.16.</span> <span class="nav-text">查询</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#插入"><span class="nav-number">1.17.</span> <span class="nav-text">插入</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#清空表"><span class="nav-number">1.18.</span> <span class="nav-text">清空表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#删除表"><span class="nav-number">1.19.</span> <span class="nav-text">删除表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#删除数据库"><span class="nav-number">1.20.</span> <span class="nav-text">删除数据库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#修复表"><span class="nav-number">1.21.</span> <span class="nav-text">修复表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#授权超级用户"><span class="nav-number">1.22.</span> <span class="nav-text">授权超级用户</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
